Modul 10 von 16 · 📖 4 min Lesezeit · ⏱ 60 min gesamt

FUTO 10 Docker Grundlagen (EN)

Inhaltsverzeichnis (6 Abschnitte)
  1. Concepts and Background
  2. Architecture Diagram
  3. Practical Steps
  4. Common Pitfalls
  5. Further Resources
  6. Knowledge Check

FUTO 10 Docker Basics

In this module, you will learn the fundamentals of containerization with Docker. You will learn how to run applications in isolated environments, create and manage images, and persistently store data. The focus is on practical application for self-hosting operations.

Concepts and Background

Docker Engine
The core software platform for creating, running, and managing containers. It consists of the Docker daemon, a REST API, and the Docker CLI.
Images
Read-only snapshots of containers that contain all necessary files, runtime environments, and configurations. Images are read-only and serve as templates for containers.
Volumes
A mechanism for persistent data storage that exists independently of a container's lifecycle. Volumes are used for databases, configuration files, and other permanent information.
docker-compose
A tool for defining and running multiple Docker container applications with YAML files. It simplifies the management of complex, networked services.
Healthchecks
Automated checks that monitor the state of a container over time. They enable automatic restarting of failed containers.

Architecture Diagram

flowchart LR
  A[Docker Host] --> B[Docker Engine]
  B --> C[Container 1]
  B --> D[Container 2]
  B --> E[Container 3]
  C --> F[Image 1]
  D --> G[Image 2]
  E --> H[Image 3]
  B --> I[Docker Volumes]
  B --> J[Docker Networks]

Practical Steps

  1. Install Docker Engine on your system. Reason: Docker is the fundamental prerequisite for all container operations.
  2. Use the command docker run -d -p 8080:80 nginx to start an Nginx container. Reason: This command creates and starts a container in the background and maps port 8080 of the host to port 80 of the container.
  3. Create a Docker volume with docker volume create mydata. Reason: Volumes enable permanent data storage, even when the container is removed.
  4. Create a Docker Compose file docker-compose.yml with a simple web application service. Reason: Docker Compose simplifies the definition and management of multi-container applications.
  5. Connect a volume to a container in docker-compose.yml with the configuration volumes:
    - mydata:/app/data. Reason: Bind mounts and volumes make data available between container restarts.
  6. Define a custom network in Docker Compose with networks:
    myapp-network:. Reason: Isolated networks improve security and communication between containers.
  7. Add a healthcheck to a service in docker-compose.yml:
    healthcheck:
    test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
    interval: 30s
    timeout: 10s
    retries: 3. Reason: Healthchecks automate monitoring of the container state.

Common Pitfalls

Further Resources

Knowledge Check

Four questions for self-assessment. Click on each question to see the correct answer and explanation.

What is the main difference between Docker Images and Containers?
  • A) Images are read-only, containers can be written to
  • B) Images are templates, containers are running instances of those templates
  • C) Images require less storage space than containers
  • D) Containers cannot exist without images, but images can exist without containers

Correct Answer: B. Images are static templates with all necessary components, while containers are running instances of these images. A is incorrect, as containers can also be read-only. C is incorrect, as images are smaller than their running containers. D is partially correct but not the main difference.

What is the main purpose of Docker Volumes?
  • A) To speed up container execution
  • B) To share configuration files between containers
  • C) To persistently store data that outlives a container's lifecycle
  • D) To increase container security

Correct Answer: C. Volumes serve for persistent data storage that exists independently of a container's lifecycle. A is incorrect, as volumes do not affect execution speed. B is incorrect, as other mechanisms like Bind Mounts are used for sharing configuration files. D is incorrect, as volumes primarily serve data storage.

What is Docker Compose mainly used for?
  • A) Creating Docker Images
  • B) Defining and running multiple container applications with YAML files
  • C) Monitoring system resources
  • D) Backing up Docker data

Correct Answer: B. Docker Compose is a tool for defining and running multiple Docker container applications with YAML files. A is incorrect, as Dockerfile is used for image creation